package com.lss.cloud.service.impl;

import com.lss.cloud.mapper.AccountMapper;
import com.lss.cloud.service.AccountService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * 2024/3/26-23:27
 * 功能:
 */
@Service
@Slf4j
public class AccountServiceImpl implements AccountService {
    @Resource
    private AccountMapper accountMapper;

    @Override
    public void decrease(Long userId, Long money) {
        log.info("---------------->进行accoutn修改 userId:{} money:{}",userId,money);
        //myTimeOut();
        //int age = 10/0;
        accountMapper.decrease(userId,money);
        log.info("----------------->account修改完毕");
    }

    /**
     * 模拟超时异常，全局事务回滚
     */
    private static void myTimeOut()
    {
        try { TimeUnit.SECONDS.sleep(65); }
        catch (InterruptedException e) { e.printStackTrace(); }
    }
}
